<?php


namespace app\model;


class User extends BaseModel
{
    protected $hidden = [
        'password', 'salt', 'is_admin', 'profile', 'delete_time', 'create_time'
    ];

    public function getSexAttr($value): string
    {
        $sex = [0 => '女', 1 => '男'];
        return $sex[$value];
    }

    public function image()
    {
        return $this->hasOne(Image::class, 'id', 'img_id');
    }

    public function check_pwd($pwd)
    {
        return $this->encryption_pwd($this->salt, $pwd) == $this->password;
    }

    public function encryption_pwd($salt, $pwd): string
    {
        return md5(md5($salt) . md5($pwd));
    }
}